package com.lxb.eduservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lxb.eduservice.entity.EduTeacher;
import com.lxb.eduservice.mapper.EduTeacherMapper;
import com.lxb.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 讲师 服务实现类
 *
 * @author testjava
 * @since 2022-10-05
 */
@Service
public class EduTeacherServiceImpl extends ServiceImpl<EduTeacherMapper, EduTeacher> implements EduTeacherService {

    /**
     * 讲师分页
     *
     * @param teacherPage
     * @return
     */
    @Override
    public Map<String, Object> pageTearchar(Page<EduTeacher> teacherPage) {

        QueryWrapper<EduTeacher> queryWrapper = new QueryWrapper();
        queryWrapper.orderByAsc("sort");

        //调用方法时,底层把分页的全部数据封装到teacherPage对象中
        baseMapper.selectPage(teacherPage, queryWrapper);

        //存放分页数据
        Map<String, Object> map = new HashMap<>();

        List<EduTeacher> records = teacherPage.getRecords();
        map.put("items", records);//每页数据list集合
        map.put("total", teacherPage.getTotal());//总记录数
        map.put("pages", teacherPage.getPages());//总页数
        map.put("current", teacherPage.getCurrent());//当前页
        map.put("size", teacherPage.getSize());//每页记录条数
        map.put("hasNext", teacherPage.hasNext());//下一页
        map.put("hasPrevious", teacherPage.hasPrevious());//上一页

        return map;
    }
}
